import pandas as pd
import matplotlib.pyplot as plt

# 读取数据集
df = pd.read_csv('order_train1_new.csv')

# 设置价格区间和价格标签d
bins = [0, 500,1000,1500, 2000, 2500,3000,3500, 4000,4500, 5000,5500]
labels = ['0-500','500-1000', '1000-1500', '1500-2000', '2000-2500', '2500-3000', '3500-4000', '4000-4500', '4500-5000', '5000-5500','5500-6000']

# 将数据进行价格区间离散化
df['price_interval'] = pd.cut(df['item_price'], bins=bins, labels=labels)

# 对数据进行分组并统计需求量
grouped = df.groupby('price_interval')['ord_qty'].sum()

# 画折线图
plt.plot(grouped.index, grouped.values)
plt.title('Demand vs Price')
plt.xlabel('Price Interval')
plt.ylabel('Demand')
plt.xticks(rotation=10) # 设置横坐标文字旋转45度

# 显示图像
plt.show()
